package com.ycfmedical.bed.local.dao;

import android.content.Context;

import com.ycfmedical.bed.greendao.gen.DaoSession;
import com.ycfmedical.bed.local.entity.User;
import com.ycfmedical.bed.utils.AssetsHelper;
import com.ycfmedical.bed.utils.GsonHelper;

import java.util.List;

/**
 * 用户信息数据访问
 * Created by Egoist on 2017/3/14.
 */
public class UserDao {
    
    private UserDao()
    {
    }

    // 所有栏目
    private static List<User> sAllUserList;

    /**
     * 更新用户信息本地数据
     * @param context
     * @param daoSession
     */
    public static void updateLocalData(Context context, DaoSession daoSession) {
        sAllUserList = GsonHelper.convertEntities(AssetsHelper.readData(context, "UserTab"), User.class);
        com.ycfmedical.bed.greendao.gen.UserDao beanDao = daoSession.getUserDao();
        if (beanDao.count() == 0) {
            beanDao.insertInTx(sAllUserList);
        }
    }

    /**
     * 获取所有用户
     * @return
     */
    public static List<User> getAllUserInfoList() {
        return sAllUserList;
    }
}
